/**
 * 
 */
package by.imotaeva.printing_services.dataaccess.impl;

import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.springframework.stereotype.Repository;

import by.imotaeva.printing_services.dataaccess.DesignOrderDao;
import by.imotaeva.printing_services.datamodel.DesignOrder;
import by.imotaeva.printing_services.datamodel.DesignOrder_;

/**
 * @author Inna
 *
 */

@Repository
public class DesignOrderDaoImpl extends AbstractDaoImpl<Long, DesignOrder>
		implements DesignOrderDao {

	protected DesignOrderDaoImpl() {
		super(DesignOrder.class);
	}

	@Override
	public DesignOrder getDesignOrderById(Long id) {
		CriteriaBuilder cBuilder = getEm().getCriteriaBuilder();

		CriteriaQuery<DesignOrder> criteria = cBuilder
				.createQuery(DesignOrder.class);
		Root<DesignOrder> root = criteria.from(DesignOrder.class);

		criteria.select(root);
		root.fetch(DesignOrder_.designExampleImg);
		root.fetch(DesignOrder_.customer);

		criteria.where(cBuilder.equal(root.get(DesignOrder_.id), id));

		TypedQuery<DesignOrder> query = getEm().createQuery(criteria);
		DesignOrder result = query.getSingleResult();
		return result;
	}

}
